package logic

import (
	"context"
	"lucky/cache"
	"lucky/luckyrpc/internal/svc"
	"lucky/luckyrpc/luckyrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartDelLogic {
	return &CartDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartDelLogic) CartDel(in *luckyrpc.CartDelRequest) (*luckyrpc.CartDelResponse, error) {
	// todo: add your logic here and delete this line
	err := cache.OrderDelete(int(in.UserId), int(in.ProductId))
	if err != nil {
		return nil, err
	}
	return &luckyrpc.CartDelResponse{
		Success: true,
		Message: "购物车清除成功",
	}, nil
}
